package com.webber.demo.common.utils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 生成线程安全的同步map，VSB移植过来的
 * @author lmz
 *
 */
public class GenerateSyncMap {

	private static boolean version = JDKVersionChecker.check("1.5.0");

	public static Class concurrentHashMapClass = null;

	static {
		try {
			concurrentHashMapClass = JDKVersionChecker.check("1.5.0") ? Class
					.forName("java.util.concurrent.ConcurrentHashMap") : null;
		} catch (ClassNotFoundException localClassNotFoundException) {
			localClassNotFoundException.printStackTrace();
		}
	}

	public static Map generate() {
		try {
			if (concurrentHashMapClass != null) {
				return (Map) concurrentHashMapClass.newInstance();
			}
			return Collections.synchronizedMap(new HashMap());
		} catch (IllegalAccessException localIllegalAccessException) {
			localIllegalAccessException.printStackTrace();
			return null;
		} catch (InstantiationException localInstantiationException) {
			localInstantiationException.printStackTrace();
		}
		return null;
	}

}
